package com.shaozi.nc.hibservice;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shaozi.data.hib.common.Hql;
import com.shaozi.data.hib.common.Where;
import com.shaozi.data.hib.dao.BaseHibDao;
import com.shaozi.data.hib.service.BaseServiceImpl;
import com.shaozi.lib.throwable.SzException;
import com.shaozi.utils.date.bean.DateBean;
import com.shaozi.nc.data.hibVO.ReportVO;

@Service(value = "reportService")
public class ReportService extends BaseServiceImpl<ReportVO> {

	@Autowired
	public ReportService(BaseHibDao<ReportVO> baseHibDao) {
		super(baseHibDao);

	}

	public List<ReportVO> listReportsByDate(String companyId, DateBean date, String timeType) throws SzException {
		String hql = "from ReportVO where isDelete=0 and remind" + timeType + "Time between " + date.getDayStart()
				+ " and " + date.getDayEnd() + " and companyId=" + companyId;
		return getDao().getDaoSupport().queryObjects(hql, -1, -1);

	}

	public List<ReportVO> findByParamsToday(Integer companyId, Integer[] uid) throws SzException {
		Hql hql = Hql.get("from ReportVO");
		Where where = Where.getWhere().eq("companyId", companyId).eq("isDelete", 0).in("uid", uid);
		Where timeStart = Where.get().betweenLongStartAndEnd("remindStartTime");
		Where timeEnd = Where.get().betweenLongStartAndEnd("remindEndTime");
		hql.add(where).add("and ((").add(timeStart).add(") or (").add(timeEnd).add("))");
		return getDao().getDaoSupport().queryObjects(hql);
	}

	public ReportVO getReport(String companyId, long reportId) throws SzException {
		ReportVO vo = getDao().getDaoSupport().loadObject(ReportVO.class, (int) reportId);
		if (vo.getIsDelete() != null && vo.getIsDelete() == 1)
			return null;
		return vo;
	}

}
